import { request } from 'ice';

interface QueryParams {
  brandId?: number;
  categoryId?: number;
  /** 报价状态 */
  status?: number;
  /** 关键字 */
  keywords?: number;
}

export interface QuoteListVO {
  // sku Id
  id: number;
  // 商品id
  productId: number;
  // 商品名称
  name: string;
  brandId: number;
  // 品牌名称
  brandName: string;
  categoryId: number;
  // 分类名称
  categoryName: string;
  // 商品主图
  mainImage: string;
  // 市场价
  marketPrice: number;
  // 规格id
  attrId?: number;
  // 规格值
  attrValue?: string;
  // 报价人数
  askNum?: number;
  // 出价人数
  bidNum?: number;
  // 报价金额
  askPrice?: number;
  // 报价阶段
  askPeriod?: number;
  // 库存数量
  storeAmount?: number;
  // 剩余数量
  remainAmount?: number;
  // 报价状态
  status?: number;
  // 报价时间
  askTime?: number;
}

/** 待报价列表 */
export const stayQuoteList = (pageParams: ICommon.PageParams, formData: QueryParams): Promise<any> => {
  const params = {
    ...pageParams,
    ...formData,
  };
  return request.get('/quote/seller/quotable/list', { params }).then((res) => ({
    total: res?.total || 0,
    list: res?.data || [],
  }));
};

/** 已报价列表 */
export const alreadyQuoteList = (pageParams: ICommon.PageParams, formData: QueryParams): Promise<any> => {
  const params = {
    ...pageParams,
    ...formData,
  };
  return request.get('/quote/seller/quoted/list', { params }).then((res) => ({
    total: res?.total || 0,
    list: res?.data || [],
  }));
};

/** 获取商品最低报价 */
export const getLowPrice = (skuId: number) => {
  return request.get('/quote/seller/low/price', { params: { skuId } });
};

// 取消报价
export const cancelQuote = (id: number) => {
  return request.get('/quote/seller/cancel', { params: { id } });
};

interface QuoteParams {
  skuId: number;
  // 报价金额
  askPrice: number;
  // 报价阶段
  askPeriod: number;
  // 库存数量
  storeAmount: number;
}

export const saveQuoteService = (data: QuoteParams) => {
  return request.post('/quote/seller/ask', data);
};
